/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.lotus.tep.ui;

import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;
import chrriis.dj.nativeswing.swtimpl.components.WebBrowserListener;
import com.lotus.tep.constant.UrlConstant;
import com.lotus.tep.constant.WebBrowserUiConstant;
import com.lotus.tep.trouble.BrowserListenerException;
import java.awt.Component;

/**
 *
 * @author arvind.sharma
 */
public class WebBrowserUi {

	private final JWebBrowser jWebBrowser_;

	private WebBrowserUi() {
		jWebBrowser_ = new JWebBrowser(JWebBrowser.destroyOnFinalization());
	}

	public static WebBrowserUi createWebBrowserUi() {
		WebBrowserUi ui = new WebBrowserUi();
		ui.jWebBrowser_.setDefaultPopupMenuRegistered(WebBrowserUiConstant.POPUP_MENU_ENABLED);
		ui.jWebBrowser_.setLocationBarVisible(WebBrowserUiConstant.LOCATION_BAR_VISIBLE);
		ui.jWebBrowser_.setButtonBarVisible(WebBrowserUiConstant.BUTTON_BAR_VISIBLE);
		ui.jWebBrowser_.setMenuBarVisible(WebBrowserUiConstant.MENUBAR_VISIBLE);
		ui.jWebBrowser_.navigate(UrlConstant.START_UP);
		return ui;
	}

	public Component getComponent() {
		return jWebBrowser_;
	}
	
	public void registerWebBrowserListener(WebBrowserListener wbl) throws BrowserListenerException{
		if(null == wbl){
			throw BrowserListenerException.createNullBrowserListenerException();
		}
		jWebBrowser_.addWebBrowserListener(wbl);
	}
}
